package com.nolon.flange.dao

import androidx.lifecycle.LiveData
import androidx.room.*
import com.nolon.flange.model.RawSolution

@Dao
interface RawSolutionDao {

    @Insert
    suspend fun insert(rawSolution: RawSolution): Long

    @Insert
    suspend fun insertAll(rawSolutions: List<RawSolution>)

    @Delete
    suspend fun delete(rawSolution: RawSolution)

    @Update
    suspend fun update(rawSolution: RawSolution)

    @Query("SELECT * FROM raw_solution_table WHERE id = :id")
    suspend fun getRawSolution(id: Int): RawSolution

    @Query("SELECT * FROM raw_solution_table WHERE project_id = :projectId ORDER BY project_id DESC")
    fun getAllByProjectIdLive(projectId: Int): LiveData<List<RawSolution>>

    @Query("DELETE  FROM raw_solution_table WHERE id = :id ")
    suspend fun deleteById(id: Int)

    @Query("DELETE  FROM raw_solution_table WHERE project_id = :projectId")
    suspend fun deleteAllByProjectId(projectId: Int)

    @Query("SELECT * FROM raw_solution_table WHERE project_id = :projectId")
    suspend fun getRawSolutionsByProjectId(projectId: Int): List<RawSolution>

}
